CPP  := /gateway/cross/gcc-linaro-5.3.1-2016.05-x86_64_arm-linux-gnueabi/bin/arm-linux-gnueabi-g++
CC   := /gateway/cross/gcc-linaro-5.3.1-2016.05-x86_64_arm-linux-gnueabi/bin/arm-linux-gnueabi-gcc

SRC_PATH := ./source/
SRC_C   := $(wildcard $(SRC_PATH)*.c)
SRC_CPP := $(wildcard $(SRC_PATH)*.cpp)
INCLUDE_PATH := /home/tronlong/mqtt/include

OBJ_PATH := ./object/
# OBJ_C   := $(patsubst:$(SRC_C)%.c,$(OBJ_PATH)%.o,$(SRC_C))
OBJ_C   := $(patsubst $(SRC_PATH)%.c, $(OBJ_PATH)%.o,   $(SRC_C))
OBJ_CPP := $(patsubst $(SRC_PATH)%.cpp, $(OBJ_PATH)%.o, $(SRC_CPP))
OBJ := $(OBJ_C) $(OBJ_CPP)

TARGET   := mqtt
LIB_FILE := mosquittopp mosquitto ssl crypto
#LIB_PATH := /gateway/rootfs/nfsroot/usr/lib
LIB_PATH := ./lib
CFLAGS   := -I $(INCLUDE_PATH) -O0 -Wall
CPPFLAGS := -I $(INCLUDE_PATH) -std=c++11 -O0 -Wall
LDFLAGS  := -L $(LIB_PATH)
LDFLAGS  += $(addprefix -l,$(LIB_FILE))

$(TARGET): $(OBJ)
	$(CPP) $^ -o $@ $(CFLAGS) $(LDFLAGS)

$(OBJ_PATH)%.o: $(SRC_PATH)%.cpp
	$(CPP) -c $< -o $@ $(CPPFLAGS)

$(OBJ_PATH)%.o: $(SRC_PATH)%.c
	$(CC) -c $< -o $@ $(CFLAGS)

clean:
	-rm -rf $(OBJ) $(TARGET)

.PHONY: all clean test